﻿#include "lvgl_power_off_anim.h"

#if 1
#define lvgl_power_off_anim_debug(format, ...) lvgl_project_debug("[lvgl power off anim]-",format,##__VA_ARGS__);
#else
#define lvgl_power_off_anim_debug(format, ...) ;
#endif


//----进出----//
void lvgl_power_off_anim_in_cb(void* arc, lv_anim_value_t v)
{
    lv_obj_set_y(arc, v);
}

void lvgl_power_off_anim_in_ready_cb(lv_anim_t* anim)
{

    lvgl_power_off_anim_debug("---------anim in ready---------");

    lv_anim_del(&lvgl_power_off_data.anim_in,NULL);

    lv_obj_set_pos(lvgl_power_off_data.cont_main, lvgl_power_off_data.main_cont_x, lvgl_power_off_data.main_cont_y);

    lvgl_group_save_focus_obj();

    lvgl_group_add_obj(&lvgl_power_off_data.cont_main);
    lvgl_group_focus_obj(&lvgl_power_off_data.cont_main);

}

void lvgl_power_off_anim_in_start(int mode, int time)
{
#if LVGL_ANIM_SWITCH

    lvgl_power_off_anim_debug("---------anim in start---------");

    lv_anim_path_init(&lvgl_power_off_data.anim_path_in);
    lv_anim_path_set_cb(&lvgl_power_off_data.anim_path_in, lv_anim_path_ease_out);
    //lv_anim_path_linear线性动画
    //lv_anim_path_step最后一步更改
    //lv_anim_path_ease_in开头很慢
    //lv_anim_path_ease_out最后慢
    //lv_anim_path_ease_in_out在开始和结束时也很慢
    //lv_anim_path_overshoot超出最终值
    //lv_anim_path_bounce从最终值反弹一点（就像撞墙一样）



    lv_anim_init(&lvgl_power_off_data.anim_in);


    lv_anim_set_exec_cb(&lvgl_power_off_data.anim_in, lvgl_power_off_anim_in_cb);
    lv_anim_set_ready_cb(&lvgl_power_off_data.anim_in, lvgl_power_off_anim_in_ready_cb);
    lv_anim_set_values(&lvgl_power_off_data.anim_in, lv_obj_get_y(lvgl_power_off_data.cont_main),lvgl_power_off_data.main_cont_y);
    lv_anim_set_time(&lvgl_power_off_data.anim_in, 300);
    lv_anim_set_var(&lvgl_power_off_data.anim_in, lvgl_power_off_data.cont_main);

    lv_anim_set_path(&lvgl_power_off_data.anim_in, &lvgl_power_off_data.anim_path_in);
    lv_anim_start(&lvgl_power_off_data.anim_in);

#else


    lvgl_power_off_anim_in_ready_cb(NULL);

#endif




}


void lvgl_power_off_anim_out_cb(void* arc, lv_anim_value_t v)
{
    lv_obj_set_y(arc, v);
}
void lvgl_power_off_anim_out_ready_cb(lv_anim_t* anim)
{

    lvgl_power_off_anim_debug("---------anim out ready---------");

    lv_anim_del(&lvgl_power_off_data.anim_out,NULL);
    lvgl_power_off_close();

}

void lvgl_power_off_anim_out_start(int mode, int time)
{

    lvgl_group_remove_obj(&lvgl_power_off_data.cont_main);

#if LVGL_ANIM_SWITCH

    lvgl_power_off_anim_debug("---------anim out start---------");

    lv_anim_path_init(&lvgl_power_off_data.anim_path_out);
    lv_anim_path_set_cb(&lvgl_power_off_data.anim_path_out, lv_anim_path_ease_in);
    //lv_anim_path_linear线性动画
    //lv_anim_path_step最后一步更改
    //lv_anim_path_ease_in开头很慢
    //lv_anim_path_ease_out最后慢
    //lv_anim_path_ease_in_out在开始和结束时也很慢
    //lv_anim_path_overshoot超出最终值
    //lv_anim_path_bounce从最终值反弹一点（就像撞墙一样）



    lv_anim_init(&lvgl_power_off_data.anim_out);


    lv_anim_set_exec_cb(&lvgl_power_off_data.anim_out, lvgl_power_off_anim_out_cb);
    lv_anim_set_ready_cb(&lvgl_power_off_data.anim_out, lvgl_power_off_anim_out_ready_cb);
    lv_anim_set_values(&lvgl_power_off_data.anim_out, lv_obj_get_y(lvgl_power_off_data.cont_main), lv_obj_get_height(lv_scr_act()));
    lv_anim_set_time(&lvgl_power_off_data.anim_out, time);
    lv_anim_set_var(&lvgl_power_off_data.anim_out, lvgl_power_off_data.cont_main);

    lv_anim_set_path(&lvgl_power_off_data.anim_out, &lvgl_power_off_data.anim_path_out);
    lv_anim_start(&lvgl_power_off_data.anim_out);

#else


    lvgl_power_off_anim_out_ready_cb(NULL);

#endif

}
//----进出----//





//----select anim----//
void lvgl_power_off_anim_select_x_cb(void* arc, lv_anim_value_t v)
{
    lv_obj_set_x(arc, v);
}

void lvgl_power_off_anim_select_x_ready_cb(lv_anim_t* anim)
{
    lvgl_power_off_anim_debug("anim select_x ready");
}

void lvgl_power_off_anim_select_x_start(int targetpos)
{
#if LVGL_ANIM_SWITCH


    lvgl_power_off_anim_debug("anim select_x start");


    lv_anim_path_init(&lvgl_power_off_data.anim_path_select_x);
    lv_anim_path_set_cb(&lvgl_power_off_data.anim_path_select_x, lv_anim_path_ease_out);
    //lv_anim_path_linear线性动画
    //lv_anim_path_step最后一步更改
    //lv_anim_path_ease_in开头很慢
    //lv_anim_path_ease_out最后慢
    //lv_anim_path_ease_in_out在开始和结束时也很慢
    //lv_anim_path_overshoot超出最终值
    //lv_anim_path_bounce从最终值反弹一点（就像撞墙一样）


    lv_anim_init(&lvgl_power_off_data.anim_select_x);


    lv_anim_set_exec_cb(&lvgl_power_off_data.anim_select_x, lvgl_power_off_anim_select_x_cb);
    lv_anim_set_ready_cb(&lvgl_power_off_data.anim_select_x, lvgl_power_off_anim_select_x_ready_cb);
    lv_anim_set_values(&lvgl_power_off_data.anim_select_x, lv_obj_get_x(lvgl_power_off_data.cont_select), targetpos);
    lv_anim_set_time(&lvgl_power_off_data.anim_select_x, 500);
    lv_anim_set_var(&lvgl_power_off_data.anim_select_x, lvgl_power_off_data.cont_select);

    lv_anim_set_path(&lvgl_power_off_data.anim_select_x, &lvgl_power_off_data.anim_path_select_x);
    lv_anim_start(&lvgl_power_off_data.anim_select_x);

#else

    lv_obj_set_x(lvgl_power_off_data.cont_main, targetpos);

#endif

}


void lvgl_power_off_anim_select_y_cb(void* arc, lv_anim_value_t v)
{
    lv_obj_set_y(arc, v);
}

void lvgl_power_off_anim_select_y_ready_cb(lv_anim_t* anim)
{

    lvgl_power_off_anim_debug("anim select_y ready");


}

void lvgl_power_off_anim_select_y_start(int targetpos)
{
#if LVGL_ANIM_SWITCH


    lvgl_power_off_anim_debug("anim select_y start");

    lv_anim_path_init(&lvgl_power_off_data.anim_path_select_y);
    lv_anim_path_set_cb(&lvgl_power_off_data.anim_path_select_y, lv_anim_path_ease_out);
    //lv_anim_path_linear线性动画
    //lv_anim_path_step最后一步更改
    //lv_anim_path_ease_in开头很慢
    //lv_anim_path_ease_out最后慢
    //lv_anim_path_ease_in_out在开始和结束时也很慢
    //lv_anim_path_overshoot超出最终值
    //lv_anim_path_bounce从最终值反弹一点（就像撞墙一样）



    lv_anim_init(&lvgl_power_off_data.anim_select_y);


    lv_anim_set_exec_cb(&lvgl_power_off_data.anim_select_y, lvgl_power_off_anim_select_y_cb);
    lv_anim_set_ready_cb(&lvgl_power_off_data.anim_select_y, lvgl_power_off_anim_select_y_ready_cb);
    lv_anim_set_values(&lvgl_power_off_data.anim_select_y, lv_obj_get_y(lvgl_power_off_data.cont_select), targetpos);
    lv_anim_set_time(&lvgl_power_off_data.anim_select_y, 500);
    lv_anim_set_var(&lvgl_power_off_data.anim_select_y, lvgl_power_off_data.cont_select);

    lv_anim_set_path(&lvgl_power_off_data.anim_select_y, &lvgl_power_off_data.anim_path_select_y);
    lv_anim_start(&lvgl_power_off_data.anim_select_y);

#else

    lv_obj_set_y(lvgl_power_off_data.cont_main, targetpos);

#endif

}

void lvgl_power_off_anim_select_w_cb(void* arc, lv_anim_value_t v)
{
    lv_obj_set_width(arc, v);
}

void lvgl_power_off_anim_select_w_ready_cb(lv_anim_t* anim)
{
    lvgl_power_off_anim_debug("anim select_w ready");



}

void lvgl_power_off_anim_select_w_start(int targetpos)
{
#if LVGL_ANIM_SWITCH


    lvgl_power_off_anim_debug("anim select_w start");

    lv_anim_path_init(&lvgl_power_off_data.anim_path_select_w);
    lv_anim_path_set_cb(&lvgl_power_off_data.anim_path_select_w, lv_anim_path_ease_out);
    //lv_anim_path_linear线性动画
    //lv_anim_path_step最后一步更改
    //lv_anim_path_ease_in开头很慢
    //lv_anim_path_ease_out最后慢
    //lv_anim_path_ease_in_out在开始和结束时也很慢
    //lv_anim_path_overshoot超出最终值
    //lv_anim_path_bounce从最终值反弹一点（就像撞墙一样）


    lv_anim_init(&lvgl_power_off_data.anim_select_w);


    lv_anim_set_exec_cb(&lvgl_power_off_data.anim_select_w, lvgl_power_off_anim_select_w_cb);
    lv_anim_set_ready_cb(&lvgl_power_off_data.anim_select_w, lvgl_power_off_anim_select_w_ready_cb);
    lv_anim_set_values(&lvgl_power_off_data.anim_select_w, lv_obj_get_width(lvgl_power_off_data.cont_select), targetpos);
    lv_anim_set_time(&lvgl_power_off_data.anim_select_w, 500);
    lv_anim_set_var(&lvgl_power_off_data.anim_select_w, lvgl_power_off_data.cont_select);

    lv_anim_set_path(&lvgl_power_off_data.anim_select_w, &lvgl_power_off_data.anim_path_select_w);
    lv_anim_start(&lvgl_power_off_data.anim_select_w);

#else

    lv_obj_set_width(lvgl_power_off_data.cont_main, targetpos);

#endif

}


void lvgl_power_off_anim_select_h_cb(void* arc, lv_anim_value_t v)
{
    lv_obj_set_height(arc, v);
}

void lvgl_power_off_anim_select_h_ready_cb(lv_anim_t* anim)
{
    lvgl_power_off_anim_debug("anim select_h ready");




}

void lvgl_power_off_anim_select_h_start(int targetpos)
{
#if LVGL_ANIM_SWITCH



    lvgl_power_off_anim_debug("anim select_h start");


    lv_anim_path_init(&lvgl_power_off_data.anim_path_select_h);
    lv_anim_path_set_cb(&lvgl_power_off_data.anim_path_select_h, lv_anim_path_ease_out);
    //lv_anim_path_linear线性动画
    //lv_anim_path_step最后一步更改
    //lv_anim_path_ease_in开头很慢
    //lv_anim_path_ease_out最后慢
    //lv_anim_path_ease_in_out在开始和结束时也很慢
    //lv_anim_path_overshoot超出最终值
    //lv_anim_path_bounce从最终值反弹一点（就像撞墙一样）



    lv_anim_init(&lvgl_power_off_data.anim_select_h);


    lv_anim_set_exec_cb(&lvgl_power_off_data.anim_select_h, lvgl_power_off_anim_select_h_cb);
    lv_anim_set_ready_cb(&lvgl_power_off_data.anim_select_h, lvgl_power_off_anim_select_h_ready_cb);
    lv_anim_set_values(&lvgl_power_off_data.anim_select_h, lv_obj_get_height(lvgl_power_off_data.cont_select), targetpos);
    lv_anim_set_time(&lvgl_power_off_data.anim_select_h, 500);
    lv_anim_set_var(&lvgl_power_off_data.anim_select_h, lvgl_power_off_data.cont_select);

    lv_anim_set_path(&lvgl_power_off_data.anim_select_h, &lvgl_power_off_data.anim_path_select_h);
    lv_anim_start(&lvgl_power_off_data.anim_select_h);

#else

    lv_obj_set_height(lvgl_power_off_data.cont_main, targetpos);

#endif

}

//----select anim----//
